package com.linewow.xhyy.nihaonew.base;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;

/**
 * Created by LXR on 2016/9/4.
 */
public abstract class VoiceMenuBase extends RelativeLayout {
    protected InputMethodManager inputMethodManager;
    protected LayoutInflater layoutInflater;
    protected Context context;
    public VoiceMenuBase(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context,attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context=context;
        inputMethodManager= (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        layoutInflater= LayoutInflater.from(context);
    }



    public VoiceMenuBase(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs);
    }

    public VoiceMenuBase(Context context) {
        super(context);
        init(context,null);
    }

    public void hideKeyboard(){
        Activity activity= (Activity) context;
        if (activity.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (activity.getCurrentFocus() != null)
                inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}
